Just kinda following the
https://en.lfsmanual.net/wiki/InSim_examples#Example_.231 and changing stuff which doesnt work, it seems that I cant keep the insim from timing out, because the game doesnt send the ISP_TINY packet. Using python 3.10
The code:
# Dependencies.
import socket
import struct
# Some constants.
INSIM_VERSION = 4
BUFFER_SIZE = 2048
# Packet types.
ISP_ISI = 1
ISP_VER = 2
ISP_TINY = 3
TINY_NONE = 0
# Initailise the socket in TCP mode.
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect to LFS.
sock.connect(('localhost', 29999))
# Pack the ISI packet into a string.
isi = struct.pack('BBBBHHBBH16s16s',
44, # Size
ISP_ISI, # Type
1, # ReqI - causes LFS to send an IS_VER.
0, # Zero
0, # UDPPort
0, # Flags
0, # Sp0
0, # Prefix
0, # Interval
b'password', # Admin
b'^3example') # IName
# Send the ISI packet to InSim.
sock.send(isi)
buffer = ''
while True:
data = sock.recv(BUFFER_SIZE)
#print(data)
if data:
data = str(data)
buffer += data
# Loop through completed packets.
while len(buffer) > 0 and len(buffer) >= ord(buffer[0]):
# Copy the packet from the buffer.
packet = buffer[:ord(buffer[0])]
buffer = buffer[ord(buffer[0]):]
print(ord(buffer[1]))
# Check packet type.
if ord(buffer[1]) == ISP_TINY:
# Unpack the TINY packet and check it for keep-alive signal.
size, type, reqi, subt = struct.unpack('BBBB', packet)
if subt == TINY_NONE:
sock.send(packet) # Respond to keep-alive.
elif ord(buffer[1]) == ISP_VER:
# Unpack the VER packet and check the InSim version.
size, type, reqi, _, version, product, insimver = struct.unpack('BBBB8s6sH')
if insimver != INSIM_VERSION:
break # Invalid version, break loop.
else:
break # Connection has closed.
# Release the socket.
sock.close()
The print(ord(buffer[1])) in the while True loop returns these values after starting the script, leaving the pits and driving around until it times out:
92
48
48
48
120
92
92
76
92
48
Idk how I would fix it